<template>
  <div>
    <el-dialog :title="dialog.title" :visible.sync="dialog.visible" width="40%">
      <el-row>
        <el-col :span="12">筛查人姓名:{{detail.childName}}</el-col>
        <el-col :span="12">筛查人生日:{{detail.birthday}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="12">性别:{{detail.sex===1?'男':''}}{{detail.sex===0?'女':''}}</el-col>
        <el-col :span="12">客户名称:{{ detail.customerName }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="12">客户电话:{{detail.customerTel}}</el-col>
      </el-row>
      <label>筛查报告</label>
      <el-row>
        <el-col :span="24">
          <el-image :src="detail.reportFile" style="width:120px;height:120px" :preview-src-list="[detail.reportFile]" width="120" height="120" />
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <a :href="detail.reportFile" download target="_blank">下载报告</a>
        </el-col>
        <el-col :span="12">
          <a :href="detail.reportFilePdf" download target="_blank">下载pdf报告</a>
        </el-col>
      </el-row>
      <label>解读</label>
      <el-row>
        <el-col :span="24">
          <el-input
            type="textarea"
            :autosize="{ minRows: 2}"
            placeholder="请输入内容"
            v-model="detail.explain"
          ></el-input>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="explain()">确 定</el-button>
        <el-button @click="dialog.visible=false">关 闭</el-button>
      </div>
    </el-dialog>
    <el-row>
      <el-form :model="queryParam" ref="queryParam" inline class="demo-form-inline">
        <el-form-item label="筛查活动" prop="activityId">
          <el-select
            clearable
            filterable
            remote
            :remote-method="activityIdRemote"
            @clear="activityIdRemote"
            :loading="loading"
            v-model="queryParam.activityId"
            placeholder="请输入关键词"
          >
            <el-option
              v-for="item in activityIdOptions"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户" prop="customerId">
          <el-select
            clearable
            filterable
            remote
            :remote-method="customerIdRemote"
            :loading="loading"
            v-model="queryParam.customerId"
            placeholder="请输入关键词"
          >
            <el-option
              v-for="item in customerIdOptions"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户电话" prop="tel">
          <el-input placeholder="客户电话" v-model="queryParam.tel" clearable></el-input>
        </el-form-item>
        <el-form-item label="解读人" prop="explainer">
          <el-select
          clearable
            filterable
            remote
            :remote-method="explainerRemote"
            :loading="loading"
            v-model="queryParam.explainer"
            placeholder="请输入关键词"
          >
            <el-option
              v-for="item in explainerOptions"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParam.status" placeholder="请选择" clearable>
            <el-option
              v-for="item in statusOptions"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
          <el-button @click="resetForm('queryParam')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card class="box-card">
          <div class="boxcard-body">
            <el-table
              :data="list"
              style="width: 100%;"
              row-key="id"
              :header-cell-style="{ 'background-color': '#EEEEEE' }"
            >
              <el-table-column label="活动名称" width="180" prop="activityName"></el-table-column>
              <el-table-column label="客户名称" width="180" prop="customerName"></el-table-column>
              <el-table-column label="客户手机" width="180" prop="customerTel"></el-table-column>
              <el-table-column label="小孩姓名" width="180" prop="childName"></el-table-column>
              <el-table-column label="文件名称" width="180" prop="fileName"></el-table-column>
              <!-- <el-table-column label="文件图片" prop="reportFile">
                <template slot-scope="scope">
                  <el-image :src="scope.row.reportFile" style="width:60px;height:60px" :preview-src-list="[scope.row.reportFile]" />
                </template>
              </el-table-column> -->
              <el-table-column label="报告上传时间" width="180" prop="uploadTime"></el-table-column>
              <el-table-column label="报告解读" width="180" prop="explain"></el-table-column>
              <el-table-column label="报告解读人名称" width="180" prop="explainerName"></el-table-column>
              <el-table-column label="解读时间" width="180" prop="explainTime"></el-table-column>
              <el-table-column label="状态" width="180" prop="status">
                <template slot-scope="scope">
                  {{scope.row.status==1?'未解读':''}}
                  {{scope.row.status==2?'已解读':''}}
                  {{scope.row.status==3?'已评价':''}}
                  {{scope.row.status==4?'已删除':''}}
                </template>
              </el-table-column>
              <el-table-column label="评价状态" width="180" prop="commentStatus">
                <template slot-scope="scope">
                  {{scope.row.commentStatus==1?'满意':''}}
                  {{scope.row.commentStatus==2?'不满意':''}}
                </template>
              </el-table-column>
              <el-table-column label="评价时间" width="180" prop="commentTime"></el-table-column>
              <el-table-column label="操作" fixed="right" width="140">
                <template slot-scope="scope">
                  <el-button type="warning" size="small" @click="detailDialog(scope.row)">解读</el-button>
                  <el-button v-if="scope.row.status!=4" type="text" size="small" @click="deleteRow(scope.row)">删除</el-button>
                  <el-button v-if="scope.row.status==4" type="text" size="small" @click="recover(scope.row)">恢复</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination">
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page.currentPage"
              :page-sizes="page.pageSizes"
              :page-size="page.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page.total"
            ></el-pagination>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { get, postJson, postXform } from "@/utils/request.js";

export default {
  components: {},
  data() {
    return {
      dialog: {
        title: "筛查报告",
        visible: false
      },
      formLabelWidth: "100px",
      list: [],
      rules: {},
      queryParam: {
        activityId: "",
        customerId: "",
        tel: "",
        explainer: "",
        status: null
      },
      page: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
        pageSizes: [10, 20, 50]
      },
      detail: {
        id: "",
        childName: "",
        birthday: "",
        sex: "",
        customerName: "",
        customerTel: "",
        explain: "",
        reportFile: "",
        reportFilePdf:"",
      },
      statusOptions: [
        { key: 1, label: "未解读" },
        { key: 2, label: "已解读" },
        { key: 3, label: "已评价" },
        { key: 4, label: "已删除" }
      ],
      activityIdOptions: [],
      customerIdOptions: [],
      explainerOptions: [],
      loading: false
    };
  },
  created() {
    this.getList();
    this.activityIdRemote();
  },
  watch: {},
  methods: {
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.getList();
    },
    detailDialog(row) {
      this.dialog.visible = true;
      this.detail = row;
      this.detail.reportFilePdf=this.detail.reportFile.substring(0,this.detail.reportFile.lastIndexOf("."))+".pdf";
    },
    async getList() {
      await get("/checkReport/page", {
        pageNum: this.page.currentPage,
        pageSize: this.page.pageSize,
        activityId: this.queryParam.activityId,
        customerId: this.queryParam.customerId,
        tel: this.queryParam.tel,
        explainer: this.queryParam.explainer,
        status: this.queryParam.status
      }).then(res => {
        this.list = res.data.data.list;
        this.page.total = Number.parseInt(res.data.data.total);
        this.page.currentPage = res.data.data.pageNum;
        this.list.forEach(item => {
          if (item.imageUrls) {
            item.imageUrls = JSON.parse(item.imageUrls);
          } else {
            item.imageUrls = [];
          }
        });
      });
    },
    explain() {
      this.dialog.visible = false;
      let param = { id: this.detail.id, explain: this.detail.explain };
      postXform("/checkReport/explain", param).then(res => {
        this.$message({ message: "操作成功", type: "success" });
        this.getList();
      });
    },
    activityIdRemote(query) {
      // if (query !== "") {
      this.loading = true;
      get("checkactivity/likeByName", { name: query }).then(res => {
        this.loading = false;
        if (res.data.data) {
          this.activityIdOptions = [];
          res.data.data.forEach(item => {
            this.activityIdOptions.push({ key: item.id, label: item.name });
          });
        }
      });
      // } else {
      //   this.activityIdOptions = [];
      // }
    },
    customerIdRemote(query) {
      if (query !== "") {
        this.loading = true;
        get("customer/likeByName", { name: query }).then(res => {
          this.loading = false;
          if (res.data.data) {
            this.customerIdOptions = [];
            res.data.data.forEach(item => {
              this.customerIdOptions.push({ key: item.id, label: item.name });
            });
          }
        });
      } else {
        this.customerIdOptions = [];
      }
    },
    explainerRemote(query) {
      if (query !== "") {
        this.loading = true;
        get("sysUser/likeByName", { name: query }).then(res => {
          this.loading = false;
          if (res.data.data) {
            this.explainerOptions = [];
            res.data.data.forEach(item => {
              this.explainerOptions.push({ key: item.id, label: item.cname });
            });
          }
        });
      } else {
        this.explainerOptions = [];
      }
    },
    resetForm(formName) {
      if (this.$refs[formName]) {
        this.$refs[formName].resetFields();
        if (formName == "queryParam") {
          this.getList();
        }
      }
    },
    deleteRow(row) {
      this.$confirm("是否删除？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$https.postXform("checkReport/delete", { id: row.id }).then(res => {
            this.$message({ message: "删除成功", type: "success" });
            this.getList();
          });
        })
        .catch(() => {});
    },
    recover(row) {
      this.$confirm("是否恢复？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$https.postXform("checkReport/recover", { id: row.id }).then(res => {
            this.$message({ message: "恢复成功", type: "success" });
            this.getList();
          });
        })
        .catch(() => {});
    }
  }
};
</script>

<style lang="less"></style>
